import { defineStore } from 'pinia'
import { ref } from 'vue'
import { userGetInfoService } from '@/api/user'

export const useUserStore = defineStore(
  'app-user-info',
  () => {
    const token = ref('')
    const setToken = (t) => {
      token.value = t 
      console.log("token到底有没有",token.value)
    }
      
    const user = ref({})
    const getUser = async () => {
      const res = await userGetInfoService() // 请求获取数据
      console.log("用户信息为" + res);
      user.value = res.data
    }
    const removeToken = () => {
      localStorage.removeItem('user-info')
      token.value = ''
      user.value = ''

      // 本地存储中删除big-user
    }
    return {
      removeToken,
      token,
      setToken,
      getUser,
      user
    }
  },
  { persist: true }
)
